package comman.duke 
{
	import flash.utils.*;
	import comman.duke.TickerItem;
	/**
	 * ...
	 * @author ...
	 */
	public class TickerMgr 
	{
		public static var SYSTIME:Number = 0;
		
		public function TickerMgr() 
		{
			this.tickers = new Vector.<TickerItem>();
			tickerMap = {}
		}
		
		private var tickers:Vector.<TickerItem>;
		public var tickerMap:Object;
		private var lastTickTime:Number = 0;
		
		public function add(item:TickerItem):void{
			if ( this.tickers.indexOf(item) == -1){
				this.tickers.push(item);
				this.tickerMap[item.name] = item;
			}
		}
		
		public function remove(name:String):void{
			var item:TickerItem = this.tickerMap[name];
			var index:int = this.tickers.indexOf(item);
			if ( index != -1){
				this.tickers.splice(index, 1);
			}
			delete this.tickerMap[name];
		}
		
		public function has(name:String):Boolean{
			return this.tickerMap[name] != null;
		}
		
		public function tick(delta:int):void{
			SYSTIME += delta;
			if ( tickers.length == 0 ) return;
			for each(var f:TickerItem in this.tickers){
				f.advanceTime(delta);
			}
		}
		
		private static var _instance:TickerMgr;
		public static function get Instance():TickerMgr{
			if ( TickerMgr._instance == null ){
				TickerMgr._instance = new TickerMgr();
			}
			return TickerMgr._instance;
		}
	}

}